

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.security.NoSuchAlgorithmException;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;

/**
 * 生成私钥文件，命令行：DES fileName
 * 
 * @author yiyongpeng
 * 
 */
public class GenKey {
	public static void main(String[] args) {
		ObjectOutputStream out = null;
		try {
			KeyGenerator keyGen = KeyGenerator.getInstance(args[0]);
			SecretKey skey = keyGen.generateKey();
			out = new ObjectOutputStream(new BufferedOutputStream(
					new FileOutputStream(args[1])));
			out.writeObject(skey);
			out.flush();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (out != null) {
				try {
					out.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
